extends Node2D


var heart_node: PackedScene = preload("res://Game/Components/Heart/heart.tscn")
var heart_number: int = 0
const HEART_ADD_TIME: float = 0.5
const HEART_DISTANCE: int = 20

onready var add_heart_tween: Tween = get_node("AddHeartTween")

func _ready() -> void:
    pass

func _draw() -> void:
    if OS.is_debug_build():
        draw_rect(Rect2(0, -30, 200, 60), Color(1, 0, 0, 1), false)
    pass

func add_heart(n: int) -> void:
    var last_heart_number: int = heart_number
    heart_number = heart_number + n
    add_heart_tween.start()

    for i in range(n):
        var h: Node2D = heart_node.instance()
        h.position = Vector2(500, -200)
        h.scale = Vector2(6.0, 6.0)
        add_child(h)
        add_heart_tween.interpolate_property(
            h,
            "position",
            h.get_position(),
            Vector2((last_heart_number + i + 1) * HEART_DISTANCE, 0),
            HEART_ADD_TIME,
            Tween.TRANS_LINEAR,
            Tween.EASE_IN)
        add_heart_tween.interpolate_property(
            h,
            "scale",
            h.scale,
            Vector2(3.0, 3.0),
            HEART_ADD_TIME,
            Tween.TRANS_LINEAR,
            Tween.EASE_IN)
        yield(get_tree().create_timer(0.5), "timeout")

    pass

func pay_health(n: int) -> bool:
    if n > heart_number or n < 0:
        return false
    return true
